package com.wu.creditmanager.dialog;

import com.wu.creditmanager.R;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.EditText;

public class EditDialogBuilder extends AlertDialog.Builder {
	private EditText editText;
	private OnInputValueListener inputValueListener;

	public EditDialogBuilder(Context context, int titleId) {
		super(context);
		editText = new EditText(context);
		editText.setSingleLine();
		setView(editText);
		setTitle(titleId);
		setPositiveButton(R.string.btn_OK,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog2, int which) {
						dialog2.dismiss();
						inputValueListener.setValue(editText.getText()
								.toString());
					}
				});
		setNegativeButton(R.string.btn_CANCEL, null);
	}

	public EditDialogBuilder setOnInputValueListener(
			OnInputValueListener onInputValueListener) {
		this.inputValueListener = onInputValueListener;
		return this;
	}

	public EditDialogBuilder setInputType(int type) {
		editText.setInputType(type);
		return this;
	}

	public EditDialogBuilder setInitText(String text) {
		editText.setText(text);
		return this;
	}

	public interface OnInputValueListener {
		void setValue(String value);
	}

}
